<template>
  <div id="head">
    <div id="infoDiv">
      <i class="el-icon-s-home"></i>
      <span id="desc">课程管理系统</span>
    </div>
    <div id="loginDiv">
      <i id="setting" class="el-icon-s-tools"></i>
      <el-avatar id="avatar" icon="el-icon-user-solid"></el-avatar>
      <el-dropdown @command="logout">
        <span class="el-dropdown-link">
          {{ username }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  name: "Head",
  data() {
    return {
      username: this.$store.getters.getUser.username
    }
  },
  methods: {
    logout() {
      this.$store.dispatch('asyncUpdateUser', '');
      this.$store.dispatch('asyncUpdateToken', '');
      //清除浏览器本地存储空间
      sessionStorage.removeItem('state');
      this.$router.push("/");
    }
  }
}
</script>

<style scoped>
#head {
  background-color: rgb(36, 47, 66);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

#loginDiv {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.el-icon-s-home, #desc {
  color: white;
  font-size: 24px;
  margin-left: 12px;
}

.el-dropdown-link, #avatar, #setting {
  color: white;
  margin-right: 25px;
}
</style>
